﻿using System;
using System.IO;
using System.Text;

namespace Moose.Common
{
    public class LogHelper
    {
        /// <summary>
        /// 保存日志
        /// </summary>
        /// <param name="logInfo">日志内容</param>
        /// <param name="logFloderHomePath">日志文件夹路径</param>
        public  void SaveLog(string logInfo,string logFloderHomePath)
        {
            try
            {
                if (!Directory.Exists(logFloderHomePath))
                    Directory.CreateDirectory(logFloderHomePath);

                if (!logFloderHomePath.EndsWith("\\"))
                    logFloderHomePath += "\\";

                string _FilePath = logFloderHomePath + DateTime.Now.ToString("yyyy-MM-dd") + ".log";
                StreamWriter _SW = new StreamWriter(_FilePath, true, Encoding.Default);
                _SW.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm;ss") + " " + logInfo);
                _SW.Flush();
                _SW.Close();
                _SW.Dispose();
                _SW = null;
            }
            catch (Exception ex)
            {
                //throw;
            }
        }
    }
}
